package com.ruge.test.网易云;

import com.netease.cloud.auth.BasicCredentials;
import com.netease.cloud.auth.Credentials;
import com.netease.cloud.services.nos.NosClient;
import com.netease.cloud.services.nos.model.ListObjectsRequest;
import com.netease.cloud.services.nos.model.NOSObjectSummary;
import com.netease.cloud.services.nos.model.ObjectListing;
import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 爱丽丝、如歌  创建于 2018/9/2 10:18
 * 说明:  TODO
 */
public class 对象存储_文件管理 {
	@Test
	public void test1() {
		String accessKey = "4046a66045934bc6b366c0d3e995aceb";
		String secretKey = "1320ab11b4cb4c9c82b8404d0dce891e";
		Credentials credentials = new BasicCredentials(accessKey, secretKey);
		NosClient nosClient = new NosClient(credentials);
		List<NOSObjectSummary> listResult = new ArrayList<NOSObjectSummary>();
		ListObjectsRequest listObjectsRequest = new ListObjectsRequest();
		listObjectsRequest.setBucketName("ruge-security");
		listObjectsRequest.setMaxKeys(50);
		ObjectListing listObjects = nosClient.listObjects(listObjectsRequest);
		do {
			listResult.addAll(listObjects.getObjectSummaries());
			if (listObjects.isTruncated()) {
				ListObjectsRequest request = new ListObjectsRequest();
				request.setBucketName(listObjectsRequest.getBucketName());
				request.setMarker(listObjects.getNextMarker());
				listObjects = nosClient.listObjects(request);
			} else {
				break;
			}
		} while (listObjects != null);

	}
}
